//
//  LHXpresentVC.m
//  blackViewC
//
//  Created by 林浩翔 on 16/5/24.
//  Copyright © 2016年 林浩翔. All rights reserved.
//

#import "LHXpresentVC.h"

#define menusBtnWH 45


@interface LHXpresentVC ()<UIGestureRecognizerDelegate>

@end
@implementation LHXpresentVC

//转场控制器
- (void)containerViewWillLayoutSubviews{
    
    CGFloat height = menusBtnWH * 4 + 5 * 3;
    CGFloat presentedY  = [UIScreen mainScreen].bounds.size.height - 30 - btnWH - height;
    
    //presentedViewController 目标控制器
    self.presentedViewController.view.frame = CGRectMake(0,presentedY, btnWH, height);

    
}

-(void)tap:(UITapGestureRecognizer*)tap{
    
    [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];

}

- (void)presentationTransitionWillBegin{
    //    注意如果通过动画实现自定义的转场，必须自己添加对应的视图
    [self.containerView addSubview:self.presentedView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    tap.delegate = self;
    [self.containerView addGestureRecognizer:tap];
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    
    CGPoint curP = [touch locationInView:self.containerView];
    
    if (CGRectContainsPoint(self.presentedView.frame, curP)) {
        return NO;
    }else
    {
        return YES;
    }
}

- (void)dismissalTransitionDidEnd:(BOOL)completed{
    //    注意，如果当销毁控制器的时候，要移除对应的视图
    [self.presentedView removeFromSuperview];
}




@end
